#!/bin/env python
import sys
import random

def main():
  try:
    f = open(sys.argv[1], 'w')
    n = int(sys.argv[2])
  except:
    print >> sys.stderr, 'usage: %s <output-file> <# nodes>' % sys.argv[0]
    sys.exit(1)
  mark = [-1] * n
  m = 0
  percent = 0
  for i in range(n):
    print >> f, '%d\t' % i,
    mark[i] = i
    k = random.randint(0, 8)
    m += k
    for z in range(k):
      while True:
        j = random.randint(0, n - 1)
        if mark[j] < i: break
      mark[j] = i
      print >> f, j,
    print >> f
    while (i + 1) * 100 >= percent * n:
      print >> sys.stderr, '[info] %d%% completed\r' % percent,
      percent += 1
  print >> sys.stderr
  print >> sys.stderr, '[info] graph generated'
  print >> sys.stderr, '[info] # nodes = %d' % n
  print >> sys.stderr, '[info] # edges = %d' % m
  sys.exit(0)

if __name__ == '__main__':
  main()
